package com.example.customviewapplication;

import android.animation.Animator;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class CircleRevealActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.circle_reveal);
        final View oval = this.findViewById(R.id.oval);
        oval.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animator animator =
                        ViewAnimationUtils.createCircularReveal(
                                oval,
                                oval.getWidth(),
                                oval.getHeight(),
                                oval.getWidth(),
                                0);
                animator.setInterpolator(
                        new AccelerateDecelerateInterpolator()
                );
                animator.setDuration(2000);
                animator.start();
            }
        });

        final View rect = this.findViewById(R.id.rect);
        rect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animator animator = ViewAnimationUtils
                        .createCircularReveal(
                                rect,
                                0,
                                0,
                                0,
                                (float) Math.hypot(rect.getWidth(),rect.getHeight())
                        );
                animator.setInterpolator(new AccelerateInterpolator());
               animator.setDuration(2000);
               animator.start();
            }
        });
    }
}
